<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<#include "/common/resources.ftl"/>
<script type="text/javascript">
	function m_submit(){
		if($('#saveOrEditForm').form('validate')){
			$.ajax({
		        type: "POST",
		        url:'${ctx}/jr/company/save_edit',
		        dataType:'JSON',
		        data:$('#saveOrEditForm').serialize(),// 你的formid
		        error: function(request) {
		            $.messager.alert("错误信息","链接超时");
		        },
		        success: function(rs) {
		        	if(rs.isSuccess=="0"){
		        	    window.location.href = 'manage';
		        	}else{
		        	    $.messager.alert("错误信息",rs.errorMsg);
		        	}
		        }
		    });
		}
	}
	function m_back(){
		window.location.href = 'manage';
	}
	
	
	$(function(){
	    //初始化页面显示div
	    var isView="${isView}";
	    initShowDiv(isView);
		//获取省份
		getProvince();
		
		var provincepId = '${model.province}';
		if(provincepId!=""){
			changCity(provincepId);
			$('#city').combobox('select','${model.city}')
		}
		
		//公司类型回填数据
		$("#authorization_id").combobox('setValues',[${model.authorization}]);
		
		//初始化类型
		var companyTypeId = '${model.companyType}';
		if(companyTypeId!=""){
			if(1==companyTypeId){
				$("#edit").hide();
			}
			showHideDiv(companyTypeId);
		}
	});
	
	//省份
	function getProvince(){
		$('#province').combobox({    
		    url:'${ctx}/common/area/queryAllArea',    
		    valueField:'id',    
		    textField:'name',
		    onSelect:function(rec){
		    	changCity(rec.id);
		    }  
		});
	}
	
	//城市
	function changCity(provincepId){
		$('#city').combobox({
      		url:'${ctx}/common/area/queryArea?parentId='+provincepId,    
	  		valueField:'id',    
	  		textField:'name',
	  		value:''
   		});
	}
	
	function showHideDiv(type){
		//$("#authorizationDiv").hide();
		//$("#zj_companyName").hide();
		//$("#other_companyName").show();
	}
	
	function initShowDiv(isView){
	  if(isView==1){
	     //编辑模式
	      $("#detailViewDiv").hide();
	      $("#detailEditorDiv").show();
	      setLogoWidth();
	  }else if(isView==0) {
	     //查看模式
	     $("#detailEditorDiv").hide();
	     $("#detailViewDiv").show();
	     setLogoWidth();
	  }else if(isView==2){
	      //新增模式
	      $("#detailViewDiv").hide();
	      $("#detailEditorDiv").show();
	      $("#cancelBtn").hide();
	  }
	}
	
/**
 * 异步文件上传
 * fileId file框id
 * showImg 显示图片img框
 * imgValue 图片隐藏域id
 */
 function uploadFile(fileId,showImg,imgValue){
 	$.ajaxFileUpload ({
		url:'${ctx}/qfbao/common/uploadFile?type=1',
		secureuri:false,
		fileElementId: fileId,
		dataType: 'json',
		success: function (data, status) {
			if(data.result=="1"){
				alert("上传成功");
				$('#'+imgValue).val(data.url);
				$('#'+showImg).attr("src", data.url).show();
				$('#'+showImg).css("width","45px");
			}else{
				alert(data.errorMsg);
			}
		},
		error: function (data, status, e){
			alert(data.errorMsg);
        }
	});
 }
function ajaxfile(fileId,showImg,imgValue){
	/*if(fileId=='file6'||fileId=='file8'){
		var ImgD = $('#'+fileId).get(0).files[0];
		checkImage(ImgD,200,50,fileId,showImg,imgValue);
	}else if(fileId=='file5'||fileId=='file7'){
		var ImgD = $('#'+fileId).get(0).files[0];
		checkImage(ImgD,101,69,fileId,showImg,imgValue);
	}else{
		uploadFile(fileId,showImg,imgValue);
	}*/
	uploadFile(fileId,showImg,imgValue);
}
//判断图片尺寸大小和格式
function checkImage(ImgD,width,height,fileId,showImg,imgValue){
	var type = ImgD.type.toLocaleLowerCase();
	if(type&&type.indexOf("png")==-1){
		alert("请上传以PNG结尾的图片");
		return;
	}
	var reader = new FileReader();
	reader.readAsDataURL(ImgD);
	reader.onload = function(theFile) {
	　　var image = new Image();
	   image.src = theFile.target.result;
	   image.onload = function() {
	   		if(this.width==width&&this.height==height){
	   			uploadFile(fileId,showImg,imgValue);
	   		}else{
	   			alert("请上传"+width+"*"+height+"尺寸图片");
	   		}
	   }
	}
 }
 //设置logo的宽度		
function setLogoWidth(){
		if("${assiantLoginLogo}"){
			$("img[name=checkH5]").css("width","45px");
		}
		if("${assiantLoginLogo}"){
			$("img[name=checkAssistant]").css("width","45px");
		}
		if("${assiantIndexLogo}"){
			$("img[name=checkAssistantIndex]").css("width","45px");
		}
		if("${assiantExitLogo}"){
			$("img[name=checkAssistantExit]").css("width","45px");
		}
		if("${developersLoginLogo}"){
			$("img[name=developersLoginLogo]").css("width","45px");
		}
		if("${developersIndexLogo}"){
			$("img[name=developersIndexLogo]").css("width","45px");
		}
		if("${agencyLoginLogo}"){
			$("img[name=agencyLoginLogo]").css("width","45px");
		}
		if("${agencyIndexLogo}"){
			$("img[name=agencyIndexLogo]").css("width","45px");
		}
}
</script>
</head>
<body>
	<div id="detailViewDiv" style="display:none">
		<div class="ipt_line_long" style="width:100%; height:50px; overflow:hidden; margin-top:20px;  ">
		 	<button class="red_100" onclick="javascript:m_back();return false;" style="background-color:#74D86A;float:right">返回</button>
	     	<button id="edit"class="red_100" onclick="javascript:initShowDiv(1);" style="float:right">编辑</button>      
  		</div>
	  	<div class="fm_sty" style="margin: 20px 0px 0px;">
			<div class="ipt_line">
				<span class="ipt_title">公司类型</span>
				${model.companyTypeName}
			</div>
			<div class="ipt_line" >
				<span class="ipt_title">公司名称</span>
				${model.companyName}
			</div>
	        <#if model.companyType=="1">
	        <div id="authorizationDiv" class="ipt_line" style="display:none;">
			  <span class="ipt_title">组合授权</span>
			  ${model.authorizationName}
		    </div>
	        </#if>
	       	<div class="ipt_line">
				<span class="ipt_title">省份</span>
				${model.provinceName}
			</div>
	       	<div class="ipt_line">
				<span class="ipt_title">城市</span>
				${model.cityName}
			</div>
	      	<div class="ipt_line">
				<span class="ipt_title">公司地址</span>
				${model.adress}
			</div>
			<div class="ipt_line">
				<span class="ipt_title">M2商户号</span>
				${model.merchantCode}
			</div>
			<div class="ipt_line">
				<span class="ipt_title">微信appId</span>
				${model.appId}
			</div>
			<div class="ipt_line">
				<span class="ipt_title">微信appSecret</span>
				${model.appSecret}
			</div>
			<div class="ipt_line">
				<span class="ipt_title">是否使用佣金</span>
				<#if model.commissionFlag==0>
					${'否'}
					<#else>
					${'是'}
				</#if>
			</div>
			<div class="ipt_line">
				<span class="ipt_title">是否使用短信</span>
				<#if model.messageFlag==0>
					${'否'}
					<#else>
					${'是'}
				</#if>
			</div>
			<div class="ipt_line">
				<span class="ipt_title">是否分销楼盘</span>
				<#if model.outsideSwitch=="1">
					${'V10分销'}
					<#else>
					${'不分销'}
				</#if>
			</div>
			<div class="ipt_line">
				<span class="ipt_title">域名</span>
				${model.domain}
			</div>
			<div class="ipt_line">
				<span class="ipt_title">分销商h5登录页logo</span>
				<img type="hidden" name="checkH5"src="${h5LoginLogo}"mbigshow showbig/>
			</div>
			<div class="ipt_line">
				<span class="ipt_title">案场助手登录页logo</span>
				<img name="checkAssistant"src="${assiantLoginLogo}"mbigshow  showbig/>
			</div>
			<div class="ipt_line">
				<span class="ipt_title">案场助手首页logo</span>
				<img name="checkAssistantIndex"src="${assiantIndexLogo}"mbigshow  showbig/>
			</div>
			<div class="ipt_line">
				<span class="ipt_title">案场助手退出页logo</span>
				<img name="checkAssistantExit"src="${assiantExitLogo}"mbigshow  showbig/>${model.assiantExitLogo}
			</div>
			<div class="ipt_line">
				<span class="ipt_title">渠道PC登录页logo</span>
				<img name="developersLoginLogo"src="${developersLoginLogo}"mbigshow  showbig/>${model.developersLoginLogo}
			</div>
			<div class="ipt_line">
				<span class="ipt_title">渠道PC首页logo</span>
				<img name="developersIndexLogo"src="${developersIndexLogo}"mbigshow  showbig/>${model.developersIndexLogo}
			</div>
			<div class="ipt_line">
				<span class="ipt_title">分销PC登录页logo</span>
			<img name="agencyLoginLogo"src="${agencyLoginLogo}"mbigshow  showbig/>${model.agencyLoginLogo}
			</div>
			<div class="ipt_line">
				<span class="ipt_title">分销PC首页logo</span>
			<img name="agencyIndexLogo"src="${agencyIndexLogo}"mbigshow  showbig/>${model.agencyIndexLogo}
			</div>
			<div class="ipt_line">
				<span class="ipt_title">公司简介</span>
				${model.introduction}
			</div>
		</div>
	</div>
  
	<div style="display:none" id="detailEditorDiv">
  		<div class="ipt_line_long" style="width:100%; height:50px; overflow:hidden; margin-top:20px;  ">
		<button class="red_100" onclick="javascript:m_back();return false;" style="background-color:#74D86A;float:right">返回</button>
		<button class="red_100" onclick="javascript:initShowDiv(0);" style="float:right" id="cancelBtn">取消</button>
	  	<button class="red_100" onclick="javascript:m_submit();return false;" style="float:right">保存</button>      
  	</div>
  	<form id="saveOrEditForm" class="loan_list_form" name="saveOrEditForm">
  		<input type="hidden" name="id" value="${model.id}" />
  		<div class="fm_sty" style="margin: 20px 0px 0px;">  
        <#if isView=="2">
         <div class="ipt_line">
			<span class="ipt_title">公司类型</span>
			<input type="text" id="companyType_id1" readonly name="companyType4" value="开发商" class="ipt_226"/>
			<input type="hidden" id="companyType_id" readonly name="companyType" value="20" class="ipt_226"/>
		</div>
		<#else>
	     <div class="ipt_line">
	     <span class="ipt_title">公司类型</span>
	     	<input type="text" id="companyType_id1" readonly name="companyType5" value="开发商" class="ipt_226"/>
		</div>
		</#if>
		<div class="ipt_line" id="other_companyName">
			<span class="ipt_title">公司名称</span>
			<input type="text" name="companyName" value="${model.companyName}" class="ipt_226"/>
		</div>
       	<div class="ipt_line">
			<span class="ipt_title">省份</span>
			<input type="text" id="province" name="province" editable="false" value="${model.province}" style="height:39px; width:263px;" required="true" missingMessage="省份不能为空！"/>
		</div>
       	<div class="ipt_line">
			<span class="ipt_title">城市</span>
			<input id="city"  name="city" editable="false" class="easyui-combobox" style="height:39px; width:263px;" value="${model.city}"/>
		</div>
      	<div class="ipt_line">
			<span class="ipt_title">公司地址</span>
			<input type="text" name="adress" value="${model.adress}" class="ipt_226" />
		</div>
		<div class="ipt_line">
			<span class="ipt_title">M2商户号</span>
			<input type="text" name="merchantCode" value="${model.merchantCode}" class="ipt_226" />
		</div>
		<div class="ipt_line">
			<span class="ipt_title">微信appId</span>
			<input type="text" name="appId" value="${model.appId}" class="ipt_226" />
		</div>
		<div class="ipt_line">
			<span class="ipt_title">微信appSecret</span>
			<input type="text" name="appSecret" value="${model.appSecret}" class="ipt_226" />
		</div>
		<div class="ipt_line">
			<span class="ipt_title">是否使用佣金</span>
			<select style="height:39px; width:263px;" id="commissionFlag" name="commissionFlag">
			<#if model.commissionFlag=='1'>
				<option value="1">是</option>
				<option value="0">否</option>
			<#else>
				<option value="0">否</option>
				<option value="1">是</option>
			</#if>
			</select>
		</div>
		<div class="ipt_line">
			<span class="ipt_title">是否使用短信</span>
			<select style="height:39px; width:263px;" id="messageFlag" name="messageFlag">
			<#if model.messageFlag=='1'>
				<option value="1">是</option>
				<option value="0">否</option>
			<#else>
				<option value="0">否</option>
				<option value="1">是</option>
			</#if>
			</select>
		</div>
		<div class="ipt_line">
			<span class="ipt_title">是否分销楼盘</span>
			<select style="height:39px; width:263px;" id="outsideSwitch" name="outsideSwitch">
			<#if model.outsideSwitch=='1'>
				<option value="1">V10分销</option>
				<option value="0">不分销</option>
			<#else>
				<option value="0">不分销</option>
				<option value="1">V10分销</option>
			</#if>
			</select>
		</div>
		<div class="ipt_line">
			<span class="ipt_title">域名</span>
			<input type="text" name="domain" value="${model.domain}" class="ipt_226" />
		</div>
		<div class="ipt_line">
			<span class="ipt_title">分销商h5登录页logo<font style="color:red">(建议上传166*55PNG图片)</font></span>
			<input type="file" name="file" id="file" value="<#if h5LoginLogo?exists >${h5LoginLogo}</#if>" class="ipt_226" onchange="ajaxfile('file','showImg','h5LoginLogo')"/>
			<img id="showImg"name="checkH5" src="${h5LoginLogo}"mbigshow  showbig/>
			<input type="hidden" id="h5LoginLogo" name="h5LoginLogo" value="${h5LoginLogo}">
		</div>
		<div class="ipt_line">
			<span class="ipt_title">案场助手登录页logo<font style="color:red">(建议上传375*270PNG图片)</font></span>
			<input type="file" name="file" id="file2" value="<#if assiantLoginLogo?exists >${assiantLoginLogo}</#if>" class="ipt_226" onchange="ajaxfile('file2','showImg2','assiantLoginLogo')"/>
			<img id="showImg2"name="checkAssistant" src="${assiantLoginLogo}"mbigshow showbig/>
			<input type="hidden" id="assiantLoginLogo" name="assiantLoginLogo" value="${assiantLoginLogo}">
		</div>
		<div class="ipt_line">
			<span class="ipt_title">案场助手首页logo<font style="color:red">(建议上传100*66PNG图片)</font></span>
			<input type="file" name="file" id="file3" value="<#if model?exists >${assiantIndexLogo}</#if>" class="ipt_226" onchange="ajaxfile('file3','showImg3','assiantIndexLogo')"/>
			<img id="showImg3"name="checkAssistantIndex" src="${assiantIndexLogo}"mbigshow showbig/>
			<input type="hidden" id="assiantIndexLogo" name="assiantIndexLogo" value="${assiantIndexLogo}">
		</div>
		<div class="ipt_line">
			<span class="ipt_title">案场助手退出页logo<font style="color:red">(建议上传75*75PNG图片)</font></span>
			<input type="file" name="file" id="file4" value="<#if model?exists >${assiantExitLogo}</#if>" class="ipt_226" onchange="ajaxfile('file4','showImg4','assiantExitLogo')"/>
			<img id="showImg4" name="checkAssistantExit"src="${assiantExitLogo}"mbigshow showbig/>
			<input type="hidden" id="assiantExitLogo" name="assiantExitLogo" value="${assiantExitLogo}">
		</div>
		<div class="ipt_line">
			<span class="ipt_title">渠道PC登录页logo <font style="color:red">(建议上传101*69PNG图片)</font></span>
			<input type="file" name="file" id="file5" value="<#if model?exists >${developersLoginLogo}</#if>" class="ipt_226" onchange="ajaxfile('file5','showImg5','developersLoginLogo')"/>
			<img id="showImg5" name="developersLoginLogo"src="${developersLoginLogo}"mbigshow  showbig/>
			<input type="hidden" id="developersLoginLogo" name="developersLoginLogo" value="${developersLoginLogo}">
		</div>
		<div class="ipt_line">
			<span class="ipt_title">分销PC登录页logo <font style="color:red">(建议上传101*69PNG图片)</font></span>
			<input type="file" name="file" id="file7" value="<#if model?exists >${agencyLoginLogo}</#if>" class="ipt_226" onchange="ajaxfile('file7','showImg7','agencyLoginLogo')"/>
			<img id="showImg7" name="agencyLoginLogo"src="${agencyLoginLogo}"mbigshow showbig/>
			<input type="hidden" id="agencyLoginLogo" name="agencyLoginLogo" value="${agencyLoginLogo}">
		</div>
		<div class="ipt_line">
			<span class="ipt_title">渠道PC首页logo <font style="color:red">(建议上传200*50PNG图片)</font></span>
			<input type="file" name="file" id="file6" value="<#if model?exists >${developersIndexLogo}</#if>" class="ipt_226" onchange="ajaxfile('file6','showImg6','developersIndexLogo')"/>
			<img id="showImg6" name="developersIndexLogo"src="${developersIndexLogo}"mbigshow  showbig/>
			<input type="hidden" id="developersIndexLogo" name="developersIndexLogo" value="${developersIndexLogo}">
		</div>
		<div class="ipt_line">
			<span class="ipt_title">分销PC首页logo <font style="color:red">(建议上传200*50PNG图片)</font></span>
			<input type="file" name="file" id="file8" value="<#if model?exists >${agencyIndexLogo}</#if>" class="ipt_226" onchange="ajaxfile('file8','showImg8','agencyIndexLogo')"/>
			<img id="showImg8" name="agencyIndexLogo"src="${agencyIndexLogo}"mbigshow  showbig/>
			<input type="hidden" id="agencyIndexLogo" name="agencyIndexLogo" value="${agencyIndexLogo}">
		</div>
	</div>
	</form>
	</div>
</body>
</html>
